**** This script conducts analysis on 2009 and 2011 policy changes

levelsof eca_ind if eca_ind>0 , local(eca_inds)
foreach i of local eca_inds {
	qui sum date if eca_ind==`i'
	scalar eca`i'd = r(min)
}

*normalized time variable for RD
capture drop t_eca09 t_eca11 t_eca12 t_eca15
gen t_eca09 = date - eca1d
gen t_eca11 = date - eca2d
gen t_eca12 = date - eca3d
gen t_eca15 = date - eca5d

capture drop t_eca_d1 t_eca_d2 cut_d1 cut_d2 
gen t_eca_d1 = date - ( eca1d + 365 ) // dummy (1-year ahead)
gen cut_d1 = t_eca_d1>=0 
gen t_eca_d2 = date - ( eca2d - 365 ) // dummy (1-year back)
gen cut_d2 = t_eca_d2>=0 

label var cut_d1 "ECA 2009"
label var cut_d2 "ECA 2011"

* broad sample conditions
* main sample, treated vessels, dropping routes with low counts, know what vessel type
* and vessel doesn't stop at intermediate port (Ensenada, El Segundo, Rosarito)
local sample_cond_RD (main_sample==1) & (treat==1) & (low_cnt_rte_ves==0) /// 
					& (vesseltype_reg~=.) & (inter_port_ind==0)
					
capture drop sample_RD_regs
gen sample_RD_regs = `sample_cond_RD'

* residual plots for RDs
* All subfigures in Figure 5
*do "${base_dir}/analysis_code/RD_resplots_full_sample.do" 

* Main Regressions
*do "${base_dir}/analysis_code/run_main_analysis.do"

* Analyze Remainers vs Leavers
* Table 2 and Table A.10
* Table A.11
*local folder rd_regs
*local table_tags main 
*do "${base_dir}/analysis_code/analyze_leaver_remainer.do" "`folder'" "`table_tags'"

* Robustness checks - bandwidth and placebos
do "${base_dir}/analysis_code/robust_bw_placebo.do"

** Robustness checks - specification
do "${base_dir}/analysis_code/robust_specif.do"

** Robustness checks - fuel calculation assumptions
do "${base_dir}/analysis_code/robust_fuel.do"

* Analysis of Interpolated Tracks
*Table A.12
do "${base_dir}/analysis_code/analyze_interpolated.do"








